db = require '../utils/connect'
async = require 'async'
sql = "select appmsgs.id,appmsgs.json from appmsgs join accounts on  appmsgs.state = 0 and appmsgs.type = 49 and appmsgs.fakeid = accounts.uin"

db.runSql sql,(err, result)->
	async.forEachSeries result, (appmsg,cb)->
		try 
			JSON.parse appmsg
		catch err
			db.runSql "delete from appmsgs where id = ? ", [appmsg.id], (err)->
				console.log err if err
		cb null
	,(err)->
		console.log err if err